/*
 * File:                TestPublisher.cs
 * Authors:             
 * Company:             Sandia National Laboratories
 * Project:             
 *
 * Copyright 2008, Sandia Corporation.  Under the terms of Contract
 * DE-AC04-94AL85000, there is a non-exclusive license for use of this work by
 * or on behalf of the U.S. Government. Export of this program may require a
 * license from the United States Government. See CopyrightHistory.txt for
 * complete details.
 *
 * Reviewers:
 * Review Date:
 * Review Comments:
 *
 * Revision History:
 *
 * $Log: TestPublisher.cs,v $
 * Revision 1.1  2008/10/31 20:52:13  bstitus
 * New testing classes.  Bug #1264
 *
 *
 */

using System;
using System.Collections.Generic;
using System.Text;

using Sandia.MVCFramework.Common;
using Sandia.MVCFramework.Data;

/*
 * 1) Track the last published data packet
 * 2) Keep a queue of all of the data packets
 * 3) Track the last added subscription
 * 4) Keep a queue of all of the added 
 *      subscriptions.  Once a subscription 
 *      is added, it is never removed from 
 *      the queue, instead it is added to 
 *      the queue of removed subscriptions.
 * 5) Track the last removed subscription
 * 6) Keep a queue of all of the removed 
 *      subscriptions
 */
namespace Sandia.MVCFramework.Test
{
    /// <summary>
    /// A class to help test data packet publishing
    /// </summary>
    public class TestPublisher : IPublisher
    {
        DataPacket lastDataPacket;
        List<DataPacket> allDataPackets;

        Dictionary<ISubscriber, Type> addedSubscriptions;
        Dictionary<ISubscriber, Type> removedSubscriptions;

        /// <summary>
        /// The last data packet published
        /// </summary>
        protected DataPacket LastDataPacket
        {
            //Read-only
            //
            get { return lastDataPacket; }
        }

        /// <summary>
        /// All data packets published
        /// </summary>
        protected List<DataPacket> AllDataPackets
        {
            //Read-only
            //
            get { return allDataPackets; }
        }

        /// <summary>
        /// The added subscriptions, even if remove was called
        /// </summary>
        protected Dictionary<ISubscriber, Type> AddedSubscriptions
        {
            //Read-only
            //
            get { return addedSubscriptions; }
        }

        /// <summary>
        /// The removed subscriptions
        /// </summary>
        protected Dictionary<ISubscriber, Type> RemovedSubscriptions
        {
            //Read-only
            //
            get { return removedSubscriptions; }
        }

        /// <summary>
        /// Class constructor
        /// </summary>
        protected TestPublisher()
        {
            //Initialize this class

            allDataPackets = new List<DataPacket>();

            addedSubscriptions = new Dictionary<ISubscriber, Type>();
            removedSubscriptions = new Dictionary<ISubscriber, Type>();
        }

        #region IPublisher Members

        /// <summary>
        /// 
        /// </summary>
        /// <param name="subscriber"></param>
        /// <param name="dataType"></param>
        public void Subscribe(ISubscriber subscriber, Type dataType)
        {
            //Add the subscription to the collection
            //
            addedSubscriptions.Add(subscriber, dataType);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="subscriber"></param>
        /// <param name="dataType"></param>
        public void RemoveSubscription(ISubscriber subscriber, Type dataType)
        {
            //Don't remove the subscription, but save add it to the 
            //collection of removed subscriptions
            //
            removedSubscriptions.Add(subscriber, dataType);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="dataPacket"></param>
        public void PublishData(DataPacket dataPacket)
        {
            //Save the data packet
            //
            lastDataPacket = dataPacket;

            //Add the data packet to the collection
            //
            allDataPackets.Add(dataPacket);
        }

        #endregion

        /// <summary>
        /// 
        /// </summary>
        public void clearAddedSubscriptions()
        {
            //Remove all of the entries in the collection
            //
            addedSubscriptions.Clear();
        }

        /// <summary>
        /// 
        /// </summary>
        public void clearRemovedSubscriptions()
        {
            //Remove all of the entries in the collection
            //
            removedSubscriptions.Clear();
        }

        /// <summary>
        /// 
        /// </summary>
        public void clearDataPackets()
        {
            //Remove all of the entries in the collection
            //
            allDataPackets.Clear();
        }
    }
}
